home *** CD-ROM | disk | FTP | other *** search
- Public Class CursorForm
- Inherits System.Windows.Forms.Form
-
- #Region " Windows Form Designer generated code "
-
- Public Sub New()
- MyBase.New()
-
- AddHandler Application.Idle, AddressOf Application_Idle
-
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
-
- End Sub
-
- 'Form overrides dispose to clean up the component list.
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
-
- RemoveHandler Application.Idle, AddressOf Application_Idle
-
-
- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
- Friend WithEvents lblStatus As System.Windows.Forms.Label
- Friend WithEvents btnMoveCursor As System.Windows.Forms.Button
- Friend WithEvents chkClipCursor As System.Windows.Forms.CheckBox
- Friend WithEvents btnSetCursor As System.Windows.Forms.Button
- Friend WithEvents btnHide As System.Windows.Forms.Button
- Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
- Friend WithEvents btnLoad As System.Windows.Forms.Button
- Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
-
- 'Required by the Windows Form Designer
- Private components As System.ComponentModel.Container
-
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- Me.btnSetCursor = New System.Windows.Forms.Button()
- Me.chkClipCursor = New System.Windows.Forms.CheckBox()
- Me.lblStatus = New System.Windows.Forms.Label()
- Me.btnMoveCursor = New System.Windows.Forms.Button()
- Me.PictureBox1 = New System.Windows.Forms.PictureBox()
- Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog()
- Me.btnLoad = New System.Windows.Forms.Button()
- Me.btnHide = New System.Windows.Forms.Button()
- Me.SuspendLayout()
- '
- 'btnSetCursor
- '
- Me.btnSetCursor.Location = New System.Drawing.Point(16, 72)
- Me.btnSetCursor.Name = "btnSetCursor"
- Me.btnSetCursor.Size = New System.Drawing.Size(120, 48)
- Me.btnSetCursor.TabIndex = 4
- Me.btnSetCursor.Text = "Show Hourglass"
- '
- 'chkClipCursor
- '
- Me.chkClipCursor.BackColor = System.Drawing.SystemColors.ControlDark
- Me.chkClipCursor.Location = New System.Drawing.Point(160, 16)
- Me.chkClipCursor.Name = "chkClipCursor"
- Me.chkClipCursor.Size = New System.Drawing.Size(256, 80)
- Me.chkClipCursor.TabIndex = 2
- Me.chkClipCursor.Text = "Clip the mouse cursor to this area"
- Me.chkClipCursor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
- '
- 'lblStatus
- '
- Me.lblStatus.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
- Me.lblStatus.Dock = System.Windows.Forms.DockStyle.Bottom
- Me.lblStatus.Location = New System.Drawing.Point(0, 245)
- Me.lblStatus.Name = "lblStatus"
- Me.lblStatus.Size = New System.Drawing.Size(480, 24)
- Me.lblStatus.TabIndex = 0
- '
- 'btnMoveCursor
- '
- Me.btnMoveCursor.Location = New System.Drawing.Point(16, 16)
- Me.btnMoveCursor.Name = "btnMoveCursor"
- Me.btnMoveCursor.Size = New System.Drawing.Size(120, 48)
- Me.btnMoveCursor.TabIndex = 1
- Me.btnMoveCursor.Text = "Move cursor to center of form"
- '
- 'PictureBox1
- '
- Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
- Me.PictureBox1.Location = New System.Drawing.Point(160, 184)
- Me.PictureBox1.Name = "PictureBox1"
- Me.PictureBox1.Size = New System.Drawing.Size(64, 48)
- Me.PictureBox1.TabIndex = 6
- Me.PictureBox1.TabStop = False
- '
- 'btnLoad
- '
- Me.btnLoad.Location = New System.Drawing.Point(16, 184)
- Me.btnLoad.Name = "btnLoad"
- Me.btnLoad.Size = New System.Drawing.Size(120, 48)
- Me.btnLoad.TabIndex = 5
- Me.btnLoad.Text = "Load Cursor from File"
- '
- 'btnHide
- '
- Me.btnHide.Location = New System.Drawing.Point(16, 128)
- Me.btnHide.Name = "btnHide"
- Me.btnHide.Size = New System.Drawing.Size(120, 48)
- Me.btnHide.TabIndex = 5
- Me.btnHide.Text = "Hide Cursor"
- '
- 'CursorForm
- '
- Me.AutoScaleBaseSize = New System.Drawing.Size(7, 17)
- Me.ClientSize = New System.Drawing.Size(480, 269)
- Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.PictureBox1, Me.btnLoad, Me.btnHide, Me.btnSetCursor, Me.chkClipCursor, Me.btnMoveCursor, Me.lblStatus})
- Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 11!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.Name = "CursorForm"
- Me.Text = "CursorForm"
- Me.ResumeLayout(False)
-
- End Sub
-
- #End Region
-
- ' move the cursor to the center of the form
-
- Private Sub btnMoveCursor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveCursor.Click
- With Me.ClientRectangle
- Cursor.Position = Me.PointToScreen(New Point(CInt(.Width / 2), CInt(.Height / 2)))
- End With
- End Sub
-
- ' clip the cursor to the client area of the ClipCursor checkbox control
-
- Private Sub chkClipCursor_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkClipCursor.CheckedChanged
- If chkClipCursor.Checked Then
- ' clip the mouse cursor
- Cursor.Clip = chkClipCursor.RectangleToScreen(chkClipCursor.ClientRectangle)
- Else
- ' free the mouse cursor
- Cursor.Clip = Nothing
- End If
- End Sub
-
- ' this event fires when the UI is idle, so we can use it to
- ' display mouse coordinates
-
- Private Sub Application_Idle(ByVal sender As System.Object, ByVal e As System.EventArgs)
- lblStatus.Text = "Mouse Position = " & Me.PointToClient(Cursor.Position).ToString
- End Sub
-
- ' changes the shape of the cursor
-
- Private Sub btnSetCursor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetCursor.Click
- If btnSetCursor.Text = "Show Hourglass" Then
- 'Cursor.Current = Cursors.WaitCursor
- Me.Cursor = Cursors.WaitCursor
- btnSetCursor.Text = "Show Default"
- Else
- 'Cursor.Current = Cursors.Default
- Me.Cursor = Cursors.Default
- btnSetCursor.Text = "Show Hourglass"
- End If
- End Sub
-
- ' hide and show the cursor
-
- Private Sub btnHide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHide.Click
- If btnHide.Text = "Hide Cursor" Then
- Cursor.Hide()
- btnHide.Text = "Show Cursor"
- Else
- Cursor.Show()
- btnHide.Text = "Hide Cursor"
- End If
- End Sub
-
- ' load a cursor from file
-
- Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
- ' Ask for a file name, exit if canceled
- OpenFileDialog1.Filter = "Cursor files|*.cur"
- If OpenFileDialog1.ShowDialog() = DialogResult.Cancel Then Exit Sub
-
- Dim c As Cursor
- Try
- ' load the cursor
- c = New Cursor(OpenFileDialog1.FileName)
- Catch ex As Exception
- MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- Exit Sub
- End Try
-
- ' display the cursor on the picturebox
- Dim gr As Graphics = PictureBox1.CreateGraphics
- gr.Clear(Color.White)
- c.DrawStretched(gr, PictureBox1.ClientRectangle)
- gr.Dispose()
-
- Me.Cursor = c
- End Sub
-
- End Class
-